<?php
if(!class_exists('XAbstractLocaleHolder', false)){
	require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'XAbstractLocaleHolder.php');
}
class XHttpLocaleHolder extends XAbstractLocaleHolder{	
	protected function load(){
		$results = preg_split("/\s*,\s*/i", XServletRequest::singleton()->header('Accept-Language'));
		$order = 1.0;
		foreach($results as $result){
			$array = preg_split("/\s*;\s*/i", $result);
			if(isset($array[1])){
				preg_match("/q=([\d\.]+)/i", $array[1], $match);
				if(isset($match[1])){
					$this->locales[$match[1]] = $array[0];
					continue;
				}
			}
			if(isset($this->locales[''.$order])){
				$order = $order - 0.01;
			}				
			$this->locales[''.$order] = $array[0];
		}
		krsort($this->locales);
		$this->locale = x_array_head($this->locales);
	}
}
?>